// page/classify/classify.js
Page({
  data: {
    isHide: 0,
    category: [
     
    ],
    details: [],
    curIndex: 0,
    toView: ""
  },
  onLoad: function (options) {
    var app = getApp()
    var that = this;
    wx.request({
      url: app.globalData.host + '&g=App&m=Category&a=category', //仅为示例，并非真实的接口地址
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        wx.getStorage({
          key: 'curIndex',
          success: function (res) {
            if (!res.data) {
              that.setData({
                curIndex: 0,

              })
            } else {
              that.setData({
                curIndex: res.data,
              })
            }
          },
        })
        that.setData({
          category: res.data.c,
          details: res.data.d,
          isHide: 1
          // feaItems: res.data.m,
          // scrollItems: res.data.t,
          // listItems: res.data.g,
          // useItems: res.data.use,
        })
 
      
      }
    })
     
  },

  switchTab(e){
      wx.setStorageSync('tnt', e.target.dataset.id) // 存储
      wx.setStorageSync('tntt', e.target.dataset.index) // 存储
    this.setData({
        toView: e.target.dataset.id,
        curIndex: e.target.dataset.index
    })

  },
  onShow: function () {

      if (wx.getStorageSync('tnt')==5){
          this.setData({
              toView:5,
              curIndex: 0
          })
      }else{
          this.setData({
              toView: wx.getStorageSync('tnt'),
              curIndex: wx.getStorageSync('tntt')
          })

      }
    var that = this
    wx.getStorage({
      key: 'toView',
      success: function (res) {
        if (!res.data) {
          that.setData({
            toView: "5"
          })
        } else {
          that.setData({
            toView: res.data
          })
        }
      },
    })
    wx.getStorage({
      key: 'curIndex',
      success: function (res) {
        if (!res.data) {
          that.setData({
            curIndex: 0
          })
        } else {
          that.setData({
            curIndex: res.data
          })
        }
      },
    })
  }, sas: function (e) {
    var text = e.detail.value
    if (text) {
      wx.navigateTo({
        url: '/page/category/sousuo?text=' + text
      })
    }

  }
})